<template>
	<div :style="{ height: height, width: width }" />
</template>

<script>
import * as echarts from 'echarts';

export default {
	props: {
		height:{
			type:String,
			default:'70px'
		},
		width:{
			type:String,
			default:'100%'
		},
		id:{
			type:String,
			default:'ec'
		},
		color:{
            type:Array,
            default:[
                {
                    areaStyle: ['rgba(16,97,204, 0.3)','rgba(17,235,210, 0.1)'],
                    itemStyle: ['rgba(16,97,204, 0.3)','rgba(17,235,210, 0.1)'],
                },{
                    areaStyle: ['rgba(205,52,42, 0.5)','rgba(235,235,21,1)'],
                    itemStyle: ['rgba(205,52,42, 0.5)','rgba(235,235,21,1)']
                }
            ]
        }
	},
	data() {
		return {
			chart:{}
		};
	},
	watch:{
		data(){
			this.init()
		}
	},
	methods:{
		init(){
            this.chart = echarts.init(this.$el);

			var data_yue = ['1月', '2月', '3月', '4月', '5月', '6月'];
            var data1 = [500, 1500, 750, 1350, 1500, 750];
            var data2 = [1100, 700, 1820, 810, 1820, 810];
            var data_l = data_yue.length;

            let option = {
                grid: {
                    left: '0',
                    right: '15',
                    bottom: '30',
                    top: '20',
                    containLabel: true,
                },
                tooltip: {
                    show: true,
                    trigger: 'axis'
                },
                legend: {
                    icon: 'rect',
                    itemWidth: 20,
                    itemHeight: 5,
                    itemGap: 10,
                    width: '100%',
                    bottom: '0',
                    right: 'center',
                    textStyle: {
                        fontSize: 16,
                        color: '#fff'
                    }
                },
                xAxis: [{
                    type: 'category',
                    boundaryGap: false,
                    axisLabel: {
                        interval: 0,
                        textStyle: {
                            color: '#fff',
                            fontSize: 16
                        }
                    },
                    axisLine: {
                        lineStyle: {
                            color: '#00fcff'
                        }
                    },
                    axisTick: {
                        show: false
                    },
                    data: data_yue
                }],
                yAxis: [{
                    type: 'value',
                    //name: '万元',
                    nameTextStyle: {
                        color: '#fff',
                        fontSize: 14,
                        padding: [0, 40, 8, 0]
                    },
                    minInterval: 500,
                    axisLabel: {
                        show: true,
                        textStyle: {
                            color: '#fff',
                            fontSize: 16
                        }
                    },
                    axisLine: {
                        lineStyle: {
                            color: '#00fcff'
                        }
                    },
                    axisTick: {
                        show: false
                    },
                    splitLine: {
                        show: true,
                        lineStyle: {
                            color: 'rgba(0, 127, 224, 0.4)',
                            type: 'dashed'
                        }
                    }
                }],
                series: [{
                    name: '车辆1',
                    type: 'line',
                    smooth: true,
                    symbol: 'circle',
                    symbolSize: 2,
                    showSymbol: false,
                    lineStyle: {
                        normal: {
                            width: 3
                        }
                    },
                    areaStyle: {
                        normal: {
                            color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                                offset: 0,
                                color: 'rgba(205,52,42, 0.5)'
                            }, {
                                offset: 0.8,
                                color: 'rgba(235,235,21, 0)'
                            }], false),
                            shadowColor: 'rgba(0, 0, 0, 0.1)',
                            shadowBlur: 10
                        },
                    },
                    itemStyle: {
                        normal: {

                            color: new echarts.graphic.LinearGradient(0, 0, 1, 0, [{
                                offset: 0,
                                color: 'rgba(205,52,42,1)'
                            }, {
                                offset: 1,
                                color: 'rgba(235,235,21,1)'
                            }])
                        }
                    },
                    data: data1
                }, {
                    name: '车辆2',
                    type: 'line',
                    smooth: true,
                    symbol: 'circle',
                    symbolSize: 2,
                    showSymbol: false,
                    lineStyle: {
                        normal: {
                            width: 3
                        }
                    },
                    areaStyle: {
                        normal: {
                            color: new echarts.graphic.LinearGradient(0, 0, 1, 0, [{
                                offset: 0,
                                color: 'rgba(16,97,204, 0.3)'
                            }, {
                                offset: 0.8,
                                color: 'rgba(17,235,210, 0.1)'
                            }], false),
                            shadowColor: 'rgba(0, 0, 0, 0.1)',
                            shadowBlur: 10
                        }
                    },
                    itemStyle: {
                        normal: {

                            color: new echarts.graphic.LinearGradient(0, 0, 1, 0, [{
                                offset: 0,
                                color: 'rgba(16,97,204,1)'
                            }, {
                                offset: 1,
                                color: 'rgba(17,235,210,1)'
                            }])
                        },
                    },
                    data: data2
                }, ]
            };

            this.chart.setOption(option);

            window.addEventListener("resize", () => {
                this.chart.resize();
            });

            var index = 0; //播放所在下标
            let this_ = this;
            setInterval(function() {
                this_.chart.dispatchAction({
                    type: 'showTip',
                    seriesIndex: 0,
                    dataIndex: index
                });
                index++;
                if (index > data_l) {
                    index = 0;
                }
            }, 2000);
		}
	},
	mounted() {
        setTimeout(() => {
			this.init()
		}, 20)
	},
};
</script>

<style scoped lang="less">
</style>
